#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n;
    cin>>n;
    map<int,int>m;
    for(int i=1;i<=n;i++){
        int a;cin>>a;
        m[a]++;
    }
    long long ans=0;
    for(auto it:m){
        if(it.second<=1)continue;
        ans+=(it.second-1)*it.first;
    }
    cout<<ans<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--)solve();
    return 0;
}
